<script setup>
import CustomNavbar from '@/pages/index/components/CustomNavbar.vue'
import XtxSwiper from '@/components/XtxSwiper.vue'
import CategoryPanel from './components/CategoryPanel.vue'
import HotPanel from './components/HotPanel.vue'
import XtxGuess from '@/components/XtxGuess.vue'
import { getHomeData } from '@/services/home'
import { getHomeCategoryData } from '@/services/homeCategory'
import { getHotMutliData } from '@/services/hotMutli'
import { ref, onMounted } from 'vue'
const homeImage = ref([])
const homeCategory = ref([])
const hotMutli = ref([])
// 获取猜你喜欢组件实例
const guessRef = ref()

// 滚动触底事件
const onScrolltolower = () => {
  console.log('滚动触底')
  guessRef.value.getMore()
}
onMounted(async () => {
  homeImage.value = []
  homeCategory.value = []
  hotMutli.value = []
  const homeRes = await getHomeData()
  const homeCategoryRes = await getHomeCategoryData()
  const hotMutliRes = await getHotMutliData()
  for (const item of homeRes.result) {
    if (item.imgUrl) {
      homeImage.value.push(item)
    }
  }
  for (const item of homeCategoryRes.result) {
    if (item.name) {
      homeCategory.value.push(item)
    }
  }
  hotMutli.value = hotMutliRes.result
  console.log(homeCategory.value)
})
</script>

<template>
  <view class="index">
    <CustomNavbar></CustomNavbar>
    <scroll-view scroll-y="true" @scrolltolower="onScrolltolower" style="height: 100vh">
      <XtxSwiper :list="homeImage"></XtxSwiper>
      <CategoryPanel :list="homeCategory"></CategoryPanel>
      <HotPanel :list="hotMutli"></HotPanel>
      <XtxGuess ref="guessRef"></XtxGuess>
    </scroll-view>
    <!--    <uni-card title="基础卡片" sub-title="副标题" extra="额外信息DLL"
      thumbnail="https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/unicloudlogo.png">
      <text>index</text>
    </uni-card> -->
  </view>
</template>

<style lang="scss">
//
</style>
